#include "occi.h"
#include <string>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <stdio.h>
using namespace oracle::occi;
using namespace std;
int main(int argc,char *argv[])
{
	string usr = "liu";
	string pwd = "liu";
	string db = "XE";

	int i_to_search = 100; 
	char strSQL[512] = {0};

	snprintf(strSQL, 512, "%s", "SELECT TO_CHAR(SYSDATE,'YYYY-MM-DD HH24:MI:SS ') FROM DUAL");

	Environment *env = Environment::createEnvironment(Environment::DEFAULT);

#if 1

	Connection *conn = env->createConnection(usr.c_str(),pwd.c_str(),db.c_str());

	Statement *stmt = conn->createStatement(strSQL);

	ResultSet *rs = NULL;
	try
	{
		rs = stmt->executeQuery();
		while(rs->next())
		{
			string r1 = rs->getString(1);
			printf("%s\n", r1.c_str());
		}
//		stmt->closeResultSet(rs);
	}
	catch(SQLException e)
	{
		if (NULL != rs)
		{
			stmt->closeResultSet(rs);
		}
		cout<<"SQLException catched:"<<e.what()<<endl;
	}

//	conn->terminateStatement(stmt);
//	env->terminateConnection(conn);

#endif
//	Environment::terminateEnvironment(env);
	return 0;
}

